<?php
class Mivec_Clone_Product extends Mivec_Clone_Abstract
{
	protected $_sqlpath;
	protected $_mainDb;
	protected $_targetDb;
	protected $_path;
	protected $_target;
	
	public function __construct(Mivec_Element_Array $_productid,$dbname)
	{
		parent::_init();
		self::_init($dbname);
		
		self::backup();
		
		return $this;
	}
	
	private function _init($dbname)
	{
		//set sql clone path
		$this->_sqlpath = $this->getConfig()->clonepath;
		
		//set db
		$this->_mainDb = $this->getConfig()->db;
		$this->_targetDb = $dbname;
		
		//set path
		$this->_path = $this->getConfig()->path;
		$this->_target = $this->getConfig()->root 
				. str_replace('_',$this->_targetDb,'.');
		
	}
	
	//create view in mysql on main db
	private function _initViews()
	{
		
	}
	
	private function _initTabls()
	{
		$this->_tables = array(
			''
		);
	}
	
	public function backup()
	{
		$_db->org = $this->_sqlpath . '/' . $this->_mainDb . '.gz';
		$_db->target = $this->_sqlpath . '/' . $this->_targetDb . '.gz';
		
		$_bakmain = "mysqldump -u root -p351608 " . $this->_mainDb . '| gzip > ' . $_db->org;
		$_baktarget = "mysqldump -u root -p351608 " . $this->_targetDb . '| gzip > ' . $_db->target;
		
		system($_bakmain);
		system($_baktarget);
		
		if (file_exists($_db->org) && file_exists($_db->target)) {
			return $this;
		}
	}
}
